home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / datatypes / mandt / source / classbase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-07  |  3.1 KB  |  138 lines

  1. /*
  2. ** $PROJECT: man.datatype
  3. **
  4. ** $VER: classbase.c 39.1 (15.11.94)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1994
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 15.11.94 : 039.001 :  initial
  16. */
  17.  
  18. #include "classbase.h"
  19.  
  20. LibCall Class *ENGINE (REGA6 struct ClassBase *cb)
  21. {
  22.    return(cb->cb_Class);
  23. }
  24.  
  25. LibCall struct Library *LibInit (REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct Library * sysbase)
  26. {
  27.    cb->cb_SegList = seglist;
  28.    cb->cb_SysBase = sysbase;
  29.    InitSemaphore (&cb->cb_Lock);
  30.  
  31.    if(cb->cb_SysBase->lib_Version >= 39)
  32.    {
  33.       cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  34.       cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  35.       cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  36.       cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  37.    } else
  38.       cb = NULL;
  39.  
  40.   return((struct Library *) cb);
  41. }
  42.  
  43. LibCall LONG LibOpen (REGA6 struct ClassBase *cb)
  44. {
  45.    LONG retval = (LONG) cb;
  46.  
  47.    ObtainSemaphore (&cb->cb_Lock);
  48.  
  49.    /* Use an internal use counter */
  50.    cb->cb_Lib.lib_OpenCnt++;
  51.    cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  52.  
  53.    if (cb->cb_Lib.lib_OpenCnt == 1)
  54.    {
  55.       retval = (LONG) NULL;
  56.  
  57.       if(cb->cb_Class == NULL)
  58.          if((cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39)))
  59.             if((cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39)))
  60.                if((cb->cb_SuperClassBase = OpenLibrary(SUPERCLASSDATATYPE,39)))
  61.                   if((cb->cb_Class = initClass(cb)))
  62.                      retval = (LONG) cb;
  63.  
  64.       if(!retval)
  65.       {
  66.          if(cb->cb_IFFParseBase)
  67.          {
  68.             CloseLibrary(cb->cb_IFFParseBase);
  69.             cb->cb_IFFParseBase = NULL;
  70.          }
  71.  
  72.          if(cb->cb_DataTypesBase)
  73.          {
  74.             CloseLibrary(cb->cb_DataTypesBase);
  75.             cb->cb_DataTypesBase = NULL;
  76.          }
  77.  
  78.          if(cb->cb_SuperClassBase)
  79.          {
  80.             CloseLibrary(cb->cb_SuperClassBase);
  81.             cb->cb_SuperClassBase = NULL;
  82.          }
  83.  
  84.          cb->cb_Lib.lib_OpenCnt--;
  85.       }
  86.    }
  87.  
  88.    ReleaseSemaphore (&cb->cb_Lock);
  89.  
  90.    return (retval);
  91. }
  92.  
  93. LibCall LONG LibClose (REGA6 struct ClassBase *cb)
  94. {
  95.    LONG retval = NULL;
  96.  
  97.    ObtainSemaphore (&cb->cb_Lock);
  98.  
  99.    if (cb->cb_Lib.lib_OpenCnt)
  100.       cb->cb_Lib.lib_OpenCnt--;
  101.  
  102.    if((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  103.    {
  104.       if(FreeClass (cb->cb_Class))
  105.       {
  106.          cb->cb_Class = NULL;
  107.          CloseLibrary(cb->cb_SuperClassBase);
  108.          CloseLibrary(cb->cb_DataTypesBase);
  109.          CloseLibrary(cb->cb_IFFParseBase);
  110.       } else
  111.          cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  112.    }
  113.  
  114.    if(cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  115.        retval = LibExpunge (cb);
  116.  
  117.    ReleaseSemaphore (&cb->cb_Lock);
  118.  
  119.    return (retval);
  120. }
  121.  
  122. LibCall LONG LibExpunge(REGA6 struct ClassBase *cb)
  123. {
  124.    BPTR seg = cb->cb_SegList;
  125.  
  126.    Remove((struct Node *) cb);
  127.  
  128.    CloseLibrary(cb->cb_UtilityBase);
  129.    CloseLibrary(cb->cb_DOSBase);
  130.    CloseLibrary(cb->cb_GfxBase);
  131.    CloseLibrary(cb->cb_IntuitionBase);
  132.  
  133.    FreeMem((APTR)((ULONG)(cb) - (ULONG)(cb->cb_Lib.lib_NegSize)), cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  134.  
  135.    return((LONG) seg);
  136. }
  137.  
  138.